package pri.zey.custom.tools;/**
 * Created by Administrator on 2016/3/16.
 */

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;

/**
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>类描述
 * 对话框工具
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>属性描述
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>方法描述
 * showProgress()---->显示默认进度对话框
 * showProgress(String msg)---->显示默认进度对话框（带文字）
 * closeProgress()---->关闭进度对话框
 */
public class TDialog {

    private TDialog mDialog;
    private ProgressDialog mProgressDialog;
    private Context mContext;

    private TDialog(Context mContext){
        this.mContext = mContext;
    }

    public TDialog getInstance(Context mContext){
        if(mDialog == null){
            mDialog = new TDialog(mContext);
        }
        return mDialog;
    }

    /**
     * 显示默认进度对话框
     */
    public void showProgress(){
        if(mProgressDialog == null){
            mProgressDialog = new ProgressDialog(mContext);
        }
        mProgressDialog.setCanceledOnTouchOutside(false);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        if(mProgressDialog != null)
            mProgressDialog.show();
    }

    /**
     * 显示默认进度对话框（带文字）
     */
    public void showProgress(String msg){
        if(mProgressDialog == null){
            mProgressDialog = new ProgressDialog(mContext);
        }
        mProgressDialog.setMessage(msg);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        if(mProgressDialog != null)
            mProgressDialog.show();
    }

    /**
     * 关闭进度对话框
     */
    public void closeProgress(){
        if(mProgressDialog != null) {
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
    }
}
